﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Petra.Gis.Geometry.Image.Tiff
{
  public partial class ImageFileDirectory
  {

    internal void prepareColorMap(Tag tag)
    {
      if ((tag.Count % 3) != 0)
      {
        throw new InvalidFileStructureException("Number of palette entries must be divideable by three without rest; " + tag.Count);
      }
      if (tag.Count < 3 || tag.Count > 768)
      {
        throw new UnsupportedTypeException("Unsupported number of palette entries: " + tag.Count + ".");
      }
      if (tag.Type != TagDataType.SHORT)
      {
        throw new UnsupportedTypeException("Unsupported number type for palette entries: " + tag.Type);
      }

      /*
      int numEntries = tag.Count / 3;
      //this.Palette = new RGBPalette(numEntries, 255);
      int vectorIndex = 0;
      for (int paletteIndex = 0; paletteIndex < numEntries; paletteIndex++)
      {
        this.Palette.putSample(RGBIndex.Red, paletteIndex, tag.getElementAsInt(vectorIndex++) >> 8);
      }
      for (int paletteIndex = 0; paletteIndex < numEntries; paletteIndex++)
      {
        this.Palette.putSample(RGBIndex.Green, paletteIndex, tag.getElementAsInt(vectorIndex++) >> 8);
      }
      for (int paletteIndex = 0; paletteIndex < numEntries; paletteIndex++)
      {
        this.Palette.putSample(RGBIndex.Blue, paletteIndex, tag.getElementAsInt(vectorIndex++) >> 8);
      }
      */
    }
  }
}
